package com.example.demo;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class SpringMVC2 {


        @RequestMapping("/r1")
        public String r1(@RequestParam("list") List<String> arr){

            return "数组为:"+ arr;
        }
    }
    @RequestMapping("r2")
    public String r2(@RequestPart("file") MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        file.transferTo(new File("S:/"+file.getOriginalFilename()));
        return "接受到的文件名称+"+file.getName();
    }

    @RequestMapping("/cookie")
    public String cookie(HttpServletRequest request, HttpServletResponse response){
        Cookie[] cookies = request.getCookies();
        if(cookies!=null){
            Arrays.stream(cookies).forEach(ck-> System.out.println(ck.getName()+":"+ck.getValue()));
        }
        return "获取cookies";
    }
}
